﻿using System;

namespace Cpu6502.Opcodes
{
    class BCS : Opcode
    {
        public BCS()
        {
            this.CpuCycles = 2;
            this.AddressType = CPU.AddressType.Relative;
        }

        public override void Execute()
        {
            if (CPU.Registers.P.C)
            {
                // Calculate CpuCycles consumed 4 if branching across a page, 3 if not
                this.CpuCycles += ((CPU.PC & 0xFF00) !=
                    ((MemoryHelper.RelativeAddress(CPU.PC, (Int16)base.Argument)) & 0xFF00) ? 2 : 1);

                CPU.PC = MemoryHelper.RelativeAddress(CPU.PC, (Int16)base.Argument);
            }
        }
    }
}
